package com.qst.rongxiaoserver.controller;

import com.qst.rongxiaoserver.common.Result;
import com.qst.rongxiaoserver.model.ReserveModel;
import com.qst.rongxiaoserver.model.dto.ReserveDto;
import com.qst.rongxiaoserver.service.IReserveService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/reserve")
@Tag(name = "预约管理")
public class ReserveController {

    @Autowired
    private IReserveService reserveService;

    @PostMapping("/add")
    @Operation(summary = "添加预约")
    public Result addReserve(@Valid @RequestBody ReserveDto reserveDto) {

       boolean res =  reserveService.addReserve(reserveDto);
       return res ? Result.success("预约成功") : Result.fail("预约失败");
    }

    //  更新预约状态
    @PutMapping("/update")
    @Operation(summary = "更新预约状态")
    public Result updateReserve(@Valid @RequestBody ReserveModel reserveModel) {
        boolean res = reserveService.updateById(reserveModel);
        return res? Result.success("更新成功") : Result.fail("更新失败");
    }

    // 根据id查询预约信息
    @GetMapping("/get/{id}")
    @Operation(summary = "根据id查询预约信息")
    public Result getReserve(@Valid @PathVariable Integer id) {
        ReserveModel reserve = reserveService.getReserveByUserId(id);
        return Result.success(reserve);
    }
    // 根据id删除预约信息
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "根据id删除预约信息")
    public Result deleteReserve(@Valid @PathVariable Integer id) {
        boolean res = reserveService.removeById(id);
        return res? Result.success("删除成功") : Result.fail("删除失败");
    }
}
